<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:composite="http://java.sun.com/jsf/composite"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:c="http://java.sun.com/jsp/jstl/core">

    <!-- INTERFACE -->
    <composite:interface>
        <composite:attribute name="labelInputHelp" required="false" default="#{cc.attrs.label}" shortDescription="La légende sur le label" ></composite:attribute>
        <composite:attribute name="label" required="false" ></composite:attribute>        
        <composite:attribute name="typeItemsValue" required="true" shortDescription="le resulta sera affecter ici (le resultat du choix)" ></composite:attribute>        
        <composite:attribute name="selectedLabel" required="false" default="#{cc.attrs.label}" ></composite:attribute>
        <composite:attribute name="selectedItem" required="false" default="" ></composite:attribute>        

        <composite:attribute name="itemsValue" required="false" shortDescription="c'est la variable List ou Map => l'ensemble d'ellémément parmit seux ou je doit faire le choix" ></composite:attribute> 
        <composite:attribute name="marginInputLabel" required="false" shortDescription="Espacement en pixel entre le label et le champ" ></composite:attribute>
        <composite:attribute name="_id" required="true" ></composite:attribute>
        <composite:attribute name="required" required="false" default="false" shortDescription="Choix obligatoire/non obligatoire" ></composite:attribute>        
        <composite:attribute name="requiredMessage" required="false" shortDescription="Mesage du loadBundle, la balise h:message sera ajouter automatiquement" ></composite:attribute>

        <composite:attribute name="updateList" required="false" shortDescription="Pour d'eclancher des Refreches ajax aprés selection de la Liste" />
        <composite:attribute name="listenerList" required="false" method-signature="void listener()" shortDescription="le listener de l'action UpdateList (ne peut accepter que une méthode avec la signiature void listener())" />   

        <!--
                <composite:attribute name="item_libelle" required="false" shortDescription="" ></composite:attribute>
                <composite:attribute name="item_value" required="false" default="false" shortDescription="" ></composite:attribute>
        -->
    </composite:interface>
        
    <!-- IMPLEMENTATION -->
    <composite:implementation>        
        &nbsp;        
        <h:outputLabel title="#{cc.attrs.labelHelp}" styleClass="selectOneMenuLabelCss" >#{cc.attrs.label}</h:outputLabel><c:if test="#{cc.attrs.required}" > <h:outputLabel value="*" style="color: red "/> </c:if>&nbsp;
        
        <c:choose>
            <c:when test="#{not empty cc.attrs.selectedItem}" >
                <p:selectOneMenu id="#{cc.attrs._id}" value="#{cc.attrs.typeItemsValue}" effect="slide" required="#{cc.attrs.required}" requiredMessage="#{cc.attrs.requiredMessage}" style="margin-left:#{cc.attrs.marginInputLabel}px; "   >
                    <f:selectItem itemLabel="#{cc.attrs.selectedLabel}" itemValue="#{cc.attrs.selectedItem}" itemDisabled="true" />

                    <c:if test="#{not empty cc.attrs.itemsValue}"> <f:selectItems value="#{cc.attrs.itemsValue}" /> </c:if>
                    <composite:insertChildren />

                </p:selectOneMenu>
            </c:when>

            <c:when test="#{empty cc.attrs.selectedItem}" >
                <p:selectOneMenu id="#{cc.attrs._id}" value="#{cc.attrs.typeItemsValue}" effect="slide" required="#{cc.attrs.required}" requiredMessage="#{cc.attrs.requiredMessage}" style="margin-left:#{cc.attrs.marginInputLabel}px; "  >
                    <f:selectItem itemLabel="#{cc.attrs.selectedLabel}" itemValue="" itemDisabled="true" />
                    <c:if test="#{not empty cc.attrs.itemsValue}"> <f:selectItems value="#{cc.attrs.itemsValue}" /> </c:if>
                    
                    <composite:insertChildren /> 

                    <c:choose>                
                        <c:when test="#{!empty cc.attrs.updateList}"> <p:ajax event="valueChange" process="@this" update="#{cc.attrs.updateList}" /> </c:when> 
                        <c:when test="#{!empty cc.attrs.listenerList}"> <p:ajax event="valueChange" process="@this" update="#{cc.attrs.updateList}" listener="#{cc.attrs.listenerList}" /> </c:when>
                        <c:otherwise></c:otherwise>
                    </c:choose>                    

                </p:selectOneMenu>                
            </c:when>
        </c:choose>

        <c:if test="#{not empty cc.attrs.requiredMessage}" >
            <p:spacer width="11px"/>
            <h:message showSummary="true" showDetail="false" style="color: red; padding-right: 11px" for="#{cc.attrs._id}"/>
        </c:if>

    </composite:implementation>
</html>


<!-- 
<c:choose>
<c:when test="{cc.attrs.modeSelected}" > <f:selectItems value="{cc.attrs.itemsValue}" var="item" itemLabel="{cc.attrs.item_libelle}" itemValue="{cc.attrs.item_value}" /> </c:when>               
<c:when test="{!empty cc.attrs.itemsValue}"> </c:when>
<c:otherwise></c:otherwise>
</c:choose>        

<h:selectOneMenu  value="{cacheRefCtrl.emploi.fonctions.numFonction}"  >
<f:selectItems value="{fonctionsContr.doLists()}" var="fonction"  itemLabel="{fonction.libelleFonction}" itemValue="{fonction.numFonction}"   />
</h:selectOneMenu>        
-->